import axios from "axios"
import BaseUrl from "@/http/url.js"
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    // console.log(1);
    // 在发送请求之前做些什么
    config.headers["Authorization"] = 'Bearer ' + localStorage.token
    config.withCredentials = true
    return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});

var http = function (methods, url, data) {
    url = BaseUrl + url
    var p = new Promise((reslove, reject) => {
        if (methods == "get") {
            axios.get(url, data).then(res => {
                reslove(res);
            }).catch(error => {
                reject(error)
            })
        }


        if (methods == "post") {
            axios.post(url, data).then(res => {
                reslove(res);
            }).catch(error => {
                reject(error)
            })
        }
    })
    return p

}

export default http



